double add(double a, double b){
cout<<a<<"+"<<b<<"="<<(a+b)<<endl;
return a+b;
}
template <typename R, typename ...Args>
struct Logger3<R(Args...)>{
Logger3(function<R(Args...)> func, const string& name): func(func), name(name) {}
R operator()(Args... args){
cout<<"Entering "<<name<<endl;
R result=func(args...);
cout<<"Exiting "<<name<<endl;
return result;
}
function<R(Args ...)> func;
string name;
};
template <typename R, typename ...Args>
auto make_logger3(R (*func)(Args...), const string& name){
return Logger3<R(Args...)>(
std::function<R(Args...)>(func), name);
}
auto logged_add=make_logger3(add, "Add");
auto result=logged_add(2, 3);